package com.lzt.test

import java.util.Properties

import com.lzt.app.Config
import org.apache.kafka.clients.consumer.{KafkaConsumer}

import scala.collection.JavaConverters

object TestKafka {
  def main(args: Array[String]): Unit = {
    val props = new Properties()
    props.put("bootstrap.servers", Config.kafkaServers)
    props.put("group.id", "test")
    props.put("enable.auto.commit", "false")
    props.put("key.deserializer", "org.apache.kafka.common.serialization.StringDeserializer")
    props.put("value.deserializer", "org.apache.kafka.common.serialization.StringDeserializer")
    val consumer = new KafkaConsumer[String, String](props)

    consumer.subscribe(JavaConverters.asJavaCollection(List(Config.kafkaNoticeTopic)))

    while(true){
      val records = consumer.poll(Long.MaxValue)
      records.forEach(x =>{
        println(s"key = ${x.key()}, value = ${x.value()}")
      })
    }
  }
}
